package com.meessiom.train.crm.reimburse.controller;


import com.meessiom.train.crm.reimburse.model.Reimburse;
import com.meessiom.train.crm.reimburse.service.ReimburseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


import java.util.Date;
import java.util.List;


@CrossOrigin("*")
@RestController
@RequestMapping("/api/v1/reimburses")
@Slf4j
public class ReimburseController {

    @Autowired
    private ReimburseService reimburseService;

    @GetMapping
    public List<Reimburse> getAllReimburses(
            @RequestParam(required = false) Long id,
            @RequestParam(required = false) String reimburseState,
            @RequestParam(required = false) String reimburseName,
            @RequestParam(required = false) String reimburseDepartment,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date reimburseDate){
        return reimburseService.getAllReimburses(id,reimburseState,reimburseName,reimburseDepartment,reimburseDate);
    }

    @PostMapping
    public Reimburse createReimburse(@RequestBody Reimburse reimburse ){
        return reimburseService.createReimburse(reimburse);
    }


    @DeleteMapping({"{id}"})
    public ResponseEntity<HttpStatus> deleteReimburse(@PathVariable long id) {
        this.reimburseService.deleteReimburse(id);
        return new ResponseEntity(HttpStatus.NO_CONTENT);






    }















}
